package com.hz.controller;

import com.aliyun.oss.common.utils.DateUtil;
import com.hz.pojo.WashHouse;
import com.hz.pojo.WashMachine;
import com.hz.service.WashHouseService;
import com.hz.service.impl.WashHouseServiceImpl;
import com.hz.utils.DateUtils;
import com.hz.utils.MassageJsons;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/WashHouse")
public class WashHouseController {

    @Resource
    private WashHouseServiceImpl washHouseService;

    @RequestMapping("/getWashMachineInfo")
    public MassageJsons getWashMachineInfo(@RequestBody HashMap<String,Long> hashMap){

        List<WashMachine> washMachineList = null;

        try {
            washMachineList = washHouseService.getWashMachineInfo(hashMap.get("washhouse_id"));
            return new MassageJsons("0","请求成功",washMachineList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new MassageJsons("1","请求失败");
    }

    @RequestMapping("/getWashMachineInfoAPP")
    public MassageJsons getWashMachineInfoAPP(Long washhouse_id){

        List<WashMachine> washMachineList = null;
        try {
            washMachineList = washHouseService.getWashMachineInfo(washhouse_id);
            return new MassageJsons("0","请求成功",washMachineList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new MassageJsons("1","请求失败");
    }

    /**
     * 获取所有洗衣房信息
     * @return
     */
    @RequestMapping("/getWashHouseAllInfo")
    public MassageJsons getWashHouseAllInfo(){

        try {
            return new MassageJsons("0","请求成功",washHouseService.getWashHouseAllInfo());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new MassageJsons("1","请求失败");
    }

    /**
     * 新增洗衣房
     * @param washHouse
     * @return
     */
    @RequestMapping("/addWashHouse")
    public MassageJsons addWashHouse(WashHouse washHouse){
        try {
            //添加洗衣房创建时间
            washHouse.setWashhouse_creation_time(DateUtils.getCurrentTime());
            washHouse.setWashhouse_state(0L);
            washHouse.setWashing_machine(0);
            washHouseService.addWashHouse(washHouse);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new MassageJsons();
    }
}
